package com.jt.controller;

import com.jt.pojo.User;
import com.jt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUser")
    public List<User> getUser(){
        List<User> users= userService.getUserList();
        return users;
    }

    @GetMapping("/user/{id}")
    public User getUser(@PathVariable Integer id){
        return userService.getUserById(id);
    }

    @PostMapping("user/{name}/{age}/{sex}")
    public String addUserRest(User user){
        userService.addUser(user);
        return "入库成功!!";
    }


}
